package com.itany.corejava.day09;

public class TestInnerClass2 {

    public static void main(String[] args) {

        OuterB outerB=new OuterB();

        MyInterface myInterface1=outerB.f1();

        //-----------------------------------------------

        myInterface1.innerF();


        MyInterface myInterface2= outerB.f2();

        myInterface2.innerF();


    }

}

class OuterB{

    private int j=2;


    public MyInterface f1(){
        int i=1;


        //局部内部类
        class InnerC implements MyInterface {

            @Override
            public void innerF() {
                System.out.println("InnerC.innerF");
                System.out.println(j);
                System.out.println(i);
            }
        }




        InnerC innerC=new InnerC();

        return innerC;
    }

    public MyInterface f2(){
        int i=1;

        //匿名内部类
        return new MyInterface(){

            @Override
            public void innerF() {
                System.out.println("OuterB.innerF");
                System.out.println(j);
                System.out.println(i);
            }

        };

    }




}


interface MyInterface{
    public void innerF();
}